import fs from 'fs';
import path from 'path';

const imagesDir = './public/images';
const outputJson = './src/_optionsImg.json';

// 允许的图片扩展名
const allowedExtensions = ['.png', '.jpg', '.jpeg'];

function getImages() {
    if (!fs.existsSync(imagesDir)) {
        console.error(`❌ 目录不存在: ${imagesDir}`);
        return [];
    }

    return fs
        .readdirSync(imagesDir)
        .filter((file) => allowedExtensions.includes(path.extname(file).toLowerCase()))
        .map((file) => ({
            value: `./images/${file}`,
            label: file
        }));
}

function writeJsonFile(data) {
    fs.writeFileSync(outputJson, JSON.stringify(data, null, 4), 'utf8');
    console.log(`✅ 生成 JSON 文件: ${outputJson}`);
}

const imagesList = getImages();
writeJsonFile(imagesList);

console.log('----copy_files over----\n');
